Skip to content

Method: ClassObjectPropertyComputer(OWLClass, OWLObjectProperty, IntegrityConstraintSet, OWLOntology)

1: package cz.cvut.kbss.jopa.owl2java;
2:
3: import cz.cvut.kbss.jopa.ic.api.ObjectParticipationConstraint;
4: import cz.cvut.kbss.jopa.ic.api.ObjectRangeConstraint;
5: import cz.cvut.kbss.jopa.model.SequencesVocabulary;
6: import java.util.Collection;
7: import java.util.HashSet;
8: import org.semanticweb.owlapi.apibinding.OWLManager;
9: import org.semanticweb.owlapi.model.IRI;
10: import org.semanticweb.owlapi.model.OWLClass;
11: import org.semanticweb.owlapi.model.OWLDataFactory;
12: import org.semanticweb.owlapi.model.OWLObjectProperty;
13: import org.semanticweb.owlapi.model.OWLOntology;
14:
15: public class ClassObjectPropertyComputer {
16:
17: private Collection<ObjectParticipationConstraint> constraints = new HashSet<>();
18: private OWLClass filler;
19: private Card card;
20:
21: public ClassObjectPropertyComputer(final OWLClass clazz,
22: final OWLObjectProperty prop,
23: final IntegrityConstraintSet set,
24: final OWLOntology merged
25: ) {
26: set.getClassObjectIntegrityConstraints(clazz, prop).forEach(ic -> {
27: if (ic instanceof ObjectParticipationConstraint) {
28: constraints.add((ObjectParticipationConstraint) ic);
29: } else if (ic instanceof ObjectRangeConstraint) {
30: filler = ((ObjectRangeConstraint) ic).getRange();
31: }
32: });
33:
34:• if (filler == null) {
35: filler = merged.getOWLOntologyManager().getOWLDataFactory().getOWLThing();
36: }
37:
38:• if (constraints.isEmpty()) {
39: card = Card.NO;
40: } else {
41: final OWLDataFactory f = merged.getOWLOntologyManager().getOWLDataFactory();
42:
43: final OWLClass object = filler;
44:
45:• if (object.getSuperClasses(merged).contains(
46: f.getOWLClass(IRI.create(SequencesVocabulary.c_List)))) {
47: this.filler = new ClassObjectPropertyComputer(object,
48: f.getOWLObjectProperty(IRI.create(SequencesVocabulary.p_element)),
49: set,
50: merged
51: )
52: .getFiller();
53: card = Card.LIST;
54:• } else if (filler.getSuperClasses(merged).contains(
55: f.getOWLClass(IRI.create(SequencesVocabulary.c_OWLSimpleList)))) {
56: this.filler = new ClassObjectPropertyComputer(object,
57: f.getOWLObjectProperty(IRI.create(SequencesVocabulary.p_hasNext)),
58: set,
59: merged
60: )
61: .getFiller();
62: card = Card.SIMPLELIST; // TODO referenced
63: } else {
64: card = Card.MULTIPLE;
65:• for (ObjectParticipationConstraint opc : constraints) {
66: OWLClass dt2 = opc.getObject();
67:• if (filler.equals(dt2)
68:• || dt2.equals(OWLManager.getOWLDataFactory()
69: .getOWLThing())) {
70:• if (opc.getMax() == 1) {
71: card = Card.ONE;
72: break;
73: }
74: }
75: }
76: }
77: }
78: }
79:
80: public Card getCard() {
81: return card;
82: }
83:
84: public OWLClass getFiller() {
85: return filler;
86: }
87:
88: public Collection<ObjectParticipationConstraint> getParticipationConstraints() {
89: return constraints;
90: }
91: }